
const deepSearch = (data: any, callback: any = () => { }, options: any = {}) => {
  let _value_key: any = options.key || 'value';
  let _value_name: any = options.label || 'label';
  let children = options.children || 'children';
  function parse(data: any, level = 0, parent: any = null) {
    for (let i = 0; i < data.length; i++) {
      let _ = data[i];
      //
      if (typeof _ != 'object') break;
      _.s__value__ = [];
      _.s__label__ = [];
      _.s__value__.push(_[_value_key]);
      _.s__label__.push(_[_value_name]);
      if (parent) {
        _.s__value__.unshift(...(parent.s__value__ ? parent.s__value__ : []));
      }
      if (parent) {
        _.s__label__.unshift(...(parent.s__label__ ? parent.s__label__ : []));
      }
      let _op = callback(_, level, parent, !(_[children] && _[children].length));
      // 结束查询
      if (_op == 'break') {
        break;
      }

      if (_op == 'stopnext') {
        continue;
      }
      //
      if (_[children] && _[children].length) {
        let nextLevel = level + 1;
        parse(_[children], nextLevel, _);
      }
    }
    return;

  }
  parse(data)
}


export { deepSearch };
